// pages/filing/list.js
const app = getApp()
Page({
    data: {
        page: 1,
        size: 10,
        total: 11,
        current:1,
        list: []
    },
    onLoad: function(options) {
        wx.showLoading({
            title: '请稍等...',
        })
        this.loadData()
    },
    loadData() {
        let {
            page = 1, current = 1, size = 10,total = 11, loading = false, list = []
        } = this.data

        if (current * size >= total || loading) return

        this.setData({
            loading: true
        })
        app.http.post('rest/archives/list?page=' + page + '&size=' + size).then(res => {
            page++
            loading = false
            total = res.content.total
            current = res.content.current
            list.push(...res.content.records)
            this.setData({
                page,
                loading,
                total,
                current,
                list
            })
            wx.hideLoading()
            wx.stopPullDownRefresh()
        }).catch(err => {
            console.log(err)
            this.setData({
                loading: false
            })
            app.wxToast.error(err.message)
        })

    },
    onReachBottom() {
        this.loadData()
    },
    onPullDownRefresh() {
        this.setData({
            page: 1,
            current:1,
            size: 10,
            total: 11,
            list: []
        })
        this.loadData()
    },

})